package com.foreveross.service;


import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.foreveross.dao.SysRoleMenuManagerDAO;
import com.foreveross.vo.SysMenu;
import com.foreveross.vo.SysRole;
import com.foreveross.vo.SysRoleMenu;

@Service("sysRoleMenuManagerService")
@Transactional
public class SysRoleMenuManagerService {

	@Resource
	SysRoleMenuManagerDAO sysRoleMenuManagerDAO;
	
	public void saveOrUpdate(String roleId,String menuIds) throws Exception{
		deleteSysRoleMenuByRoleId(roleId);
		
		SysRole sysRole = new SysRole();
		sysRole.setId(roleId);
		for(String menuId :menuIds.split(",")){
			SysRoleMenu sysRoleMenu = new SysRoleMenu();
			SysMenu sysMenu = new SysMenu();
			sysMenu.setId(menuId);
			sysRoleMenu.setSysMenu(sysMenu);
			sysRoleMenu.setSysRole(sysRole);
			
			sysRoleMenuManagerDAO.save(sysRoleMenu);
		}
		
	}


	public void deleteSysRoleMenuByRoleId(String roleIds) throws Exception{
		for(String roleId :roleIds.split(",")){
			sysRoleMenuManagerDAO.deleteSysRoleMenuByRoleId(roleId);
		}
	}
	
}
